package state

import (
	"errors"
	"fmt"
)

type tDefaultState struct {
	context iFileStreamContext
}

func newDefaultState(context iFileStreamContext) iFileStreamState {
	return &tDefaultState{
		context,
	}
}

func (me *tDefaultState) OpenRead() error {
	fmt.Printf("tDefaultState.OpenRead, file=%s\n", me.context.File())
	me.context.Switch(newReadingState(me.context))
	return nil
}

func (me *tDefaultState) OpenWrite() error {
	fmt.Printf("tDefaultState.OpenWrite, file=%s\n", me.context.File())
	me.context.Switch(newWritingState(me.context))
	return nil
}


func (me *tDefaultState) Read(p []byte) (n int, err error) {
	return 0, errors.New(fmt.Sprintf("tDefaultState.Read, file not opened, %s", me.context.File()))
}

func (me *tDefaultState) Write(p []byte) (n int, err error) {
	return 0, errors.New(fmt.Sprintf("tDefaultState.Write, file not opened, %s", me.context.File()))
}

func (me *tDefaultState) Close() error {
	fmt.Printf("tDefaultState.Close, file=%s\n", me.context.File())
	me.context.Switch(newClosedState(me.context))
	return nil
}